import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

@Component({
  selector: 'app-register',
  templateUrl: './register.component.html',
  styleUrls: ['./register.component.scss']
})
export class RegisterComponent implements OnInit {
  registerFrom: FormGroup;
  items: string[];
  private readonly avatarName = 'avatars'
  constructor(private fb: FormBuilder) { }

  ngOnInit() {
    const img = `${this.avatarName}:svg-${Math.floor(Math.random() * 16).toFixed(0)}`;
    const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
    //处理数返回一给新的数组
    this.items = nums.map(d => `avatars:svg-${d}`);
    this.registerFrom = this.fb.group({
      email: [''],
      name: [''],
      password: [''],
      repeat: [''],
      avatar: [img],
      dateOfBirth: []
    })

  }
  onSubmit({value,valid},ev){
    ev.preventDefault();

    // 如果 表单验证未通过
    if(!valid){
      return
    }
    console.log(JSON.stringify(value));
    console.log(JSON.stringify(valid))
    // 动态指定 验证器
    //this.loginForm.controls['email'].setValidators(this.validate)
  }

}
